import 'package:flutter/material.dart';

class WaveProgressIndicator extends StatefulWidget {
  final double progress;
  final Color progressColor;

  const WaveProgressIndicator({
    Key? key,
    this.progress = 0.0,
    this.progressColor = Colors.blue,
  }) : super(key: key);

  @override
  _WaveProgressIndicatorState createState() => _WaveProgressIndicatorState();
}

class _WaveProgressIndicatorState extends State<WaveProgressIndicator>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    )..repeat();
    _controller.addListener(() {
      setState(() {});
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      painter: WavePainter(
        progress: widget.progress,
        progressColor: widget.progressColor,
        animationValue: _controller.value,
      ),
    );
  }
}

class WavePainter extends CustomPainter {
  final double progress;
  final Color progressColor;
  final double animationValue;

  WavePainter({
    required this.progress,
    required this.progressColor,
    required this.animationValue,
  });

  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()..color = progressColor;
    final progressWidth = size.width * progress;
    final waveHeight = 10.0;
    final waveOffset = size.height / 4;
    final waveX = animationValue * size.width;

    for (var x = -size.width; x < size.width * 2; x += 5) {
      canvas.drawPath(
        Path()
          ..moveTo(x.toDouble() - waveX + progressWidth, waveOffset)
          ..quadraticBezierTo(
            x.toDouble() + waveX + progressWidth - 5,
            waveOffset - waveHeight,
            x.toDouble() + waveX + progressWidth,
            waveOffset,
          )
          ..quadraticBezierTo(
            x.toDouble() + waveX + progressWidth + 5,
            waveOffset + waveHeight,
            x.toDouble() - waveX + progressWidth + 10,
            waveOffset,
          ),
        paint,
      );
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}
